//
//  JZHHowLookMeViewController.m
//  极致荟
//
//  Created by hetao on 14-5-12.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHHowLookMeViewController.h"
#import "JZHPersonaldetailsViewController.h"
#import "JZHAttentionTableViewCell.h"
#import "OtherUsers.h"
@interface JZHHowLookMeViewController ()
{
    NSMutableArray *ouser;
}

@end

@implementation JZHHowLookMeViewController


- (id)initType:(int) type activit:(id)act
{
    self =[[JZHHowLookMeViewController alloc]init];
    if(self)
    {
        if([act isKindOfClass:[JZHActivities class]])
        {
            self.act=act;
        }else
        {
            self.com=act;
        }
        self.listType=type;
        
    }
    return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    ouser=[[NSMutableArray alloc]init];
    if(self.listType==1 || self.listType==4)
    {
        self.navigationItem.title=@"参加人员";
        [self loadActHttpData];
    }
   
    if(self.listType==2)
    {
        self.navigationItem.title=@"喜欢人员";
        [self likeComHttpData];

    }
    if(self.listType==3)
    {
        self.navigationItem.title=@"来访人员";
        [self laifangComHttpData];
    }
    //设置左侧按钮
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    if(OSVersionIsAtLeastiOS7>=7.0)
    {
        self.automaticallyAdjustsScrollViewInsets=NO;
    }
}

- (void)leftDrawerButtonPress:(UIButton *)but
{
    //[self.navigationController popViewControllerAnimated:YES];
    [UINavigationController Pop:self];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


///获取参加活动人员列表
- (void)loadActHttpData
{
    NSString *key=@"";
    NSString *urlpath=@"";
    if(self.listType==1)
    {
        key=@"partyId";
        urlpath=JZHHTTPURL(@"party/partyJoinList");
    }else
    {
        key=@"clubId";
        urlpath=JZHHTTPURL(@"club/clubJoinList");
    }
   
    NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithInt:self.act.actId],key,nil];
    [HttpRequest httpRequestPost:urlpath parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        NSLog(@"%@",data);
        if(rerurncode==0)
        {
            NSArray *dataarr=[data objectForKey:@"data"];
            for(NSDictionary *datadic in dataarr)
            {
                OtherUsers *ousers=[[OtherUsers alloc]init];
                ousers.userId=[[datadic objectForKey:@"userID"] intValue];
                ousers.userHeadImage=[datadic objectForKey:@"userAvatar"];
                ousers.name=[datadic objectForKey:@"userName"];
                ousers.jobdic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"userJob"],@"name", nil];
                ousers.persdic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"userProfession"],@"name", nil];
                ousers.locationdic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"userCity"],@"cityName", nil];
                [ouser addObject:ousers];
            }
            [self.table reloadData];
           
        }else{
            [MMProgressHUD showInformationWithTips:@"数据加载失败"];
        }
    }];

}

///获取喜欢商品人员列表
- (void)likeComHttpData
{
      NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithInt:self.com.comid],@"favoriteId",@"topic_content",@"favoriteType",nil];
    [HttpRequest httpRequestPost:JZHHTTPURL(@"favorite/favoriteList") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        NSLog(@"%@",data);
        if(rerurncode==0)
        {
            NSArray *dataarr=[data objectForKey:@"data"];
            for(NSDictionary *datadic in dataarr)
            {
                OtherUsers *ousers=[[OtherUsers alloc]init];
                ousers.userId=[[datadic objectForKey:@"userID"] intValue];
                ousers.userHeadImage=[datadic objectForKey:@"userAvatar"];
                ousers.name=[datadic objectForKey:@"userName"];
                ousers.jobdic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"userJob"],@"name", nil];
                ousers.persdic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"userProfession"],@"name", nil];
                ousers.locationdic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"userCity"],@"cityName", nil];
                [ouser addObject:ousers];
            }
            [self.table reloadData];
            
        }else{
            [MMProgressHUD showInformationWithTips:@"数据加载失败"];
        }
    }];

}

///来访人员列表
- (void)laifangComHttpData
{
   // [MMProgressHUD showWithStatus:@"数据加载中..."];
    NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithInt:self.com.comid],@"footmarkId",@"topic_content",@"footmarkType",nil];
    [HttpRequest httpRequestPost:JZHHTTPURL(@"footmark/footmarkList") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        NSLog(@"%@",data);
        if(rerurncode==0)
        {
            NSArray *dataarr=[data objectForKey:@"data"];
            for(NSDictionary *datadic in dataarr)
            {
                OtherUsers *ousers=[[OtherUsers alloc]init];
                ousers.userId=[[datadic objectForKey:@"userID"] intValue];
                ousers.userHeadImage=[datadic objectForKey:@"userAvatar"];
                ousers.name=[datadic objectForKey:@"userName"];
                ousers.jobdic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"userJob"],@"name", nil];
                ousers.persdic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"userProfession"],@"name", nil];
                ousers.locationdic=[[NSDictionary alloc] initWithObjectsAndKeys:[datadic objectForKey:@"userCity"],@"cityName", nil];
                [ouser addObject:ousers];
            }
            [self.table reloadData];
            //[MMProgressHUD dismiss];
        }else{
            [MMProgressHUD showInformationWithTips:@"数据加载失败"];
        }
    }];
    
}

#pragma mark ---tableview代理---
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return ouser.count;
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str=@"adf";
    JZHAttentionTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];
    if(!cell)
    {
        cell=[[[NSBundle mainBundle]loadNibNamed:@"JZHAttentionTableViewCell" owner:self options:nil] objectAtIndex:0];
        cell.time.hidden=NO;
    }
    if(self.listType>0)
    {
        [cell addACTCellData:ouser[indexPath.row]];
    }
    
    
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 71;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    [self.navigationController pushViewController:[JZHPersonaldetailsViewController shareName:ouser[indexPath.row]] animated:YES];
    
}
@end
